/*
    This file is part of libcloak.

    libcloak is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    libcloak is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with libcloak.  If not, see <http://www.gnu.org/licenses/>.

*/



#include "../include/TextResource.h"
#include <string.h>

namespace Cloak
{
	
	
	TextResource::TextResource(const string &name) : buffer(NULL), buf_len(0)
	{
		this->name = name;
		
		buffer = loadResource(this->name,&buf_len);
		
		if(buffer == NULL)
			loaded = false;
		
		loaded = true;
	}
	
	TextResource::TextResource(TextResource &old) : Resource(old), 
						        buf_len(old.buf_len)
	{
		if(old.buffer != NULL)
		{
			char *temp = new char[buf_len];
			strncpy(temp,old.buffer,buf_len);
			buffer = temp;
		}
		else
			buffer = NULL;
	}
	
	TextResource::~TextResource() 
	{
		clean();
	}
	
	
	void TextResource::clean()
	{
		if(buffer != NULL)
		{
			delete buffer;
			buffer = NULL;
		}
	}
	
	const char* TextResource::getBuffer()
	{
		return buffer;
	}
	
}

